/*
 * 〈描述〉
 *
 * @author chenxing
 * @since 版本号
 */

package com.maorioi.failureanalyzer.component;

import com.maorioi.failureanalyzer.model.Project;
import com.maorioi.failureanalyzer.other.YamlPropertySourceFactory;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;
import org.springframework.validation.annotation.Validated;

import javax.validation.constraints.NotNull;
import java.util.Map;
import java.util.Optional;

/**
 * 〈一句话功能简述〉
 *
 * <p>〈功能详细描述〉
 *
 * @author chenxing
 * @since 版本号
 */
@ConfigurationProperties("project")
@PropertySource(value = "classpath:git-project.yml", factory = YamlPropertySourceFactory.class)
@Component
@Validated
public class GitProjectData {
    @NotNull
    private Map<String, Project> data;
    @NotNull
    private String url;
    private Optional<String> maintainerMobile;

    public Project getProjectByName(String name) {
        return this.data.get(name);
    }

    public boolean hasProject(String name) {
        return this.data.containsKey(name);
    }


    public void setData(Map<String, Project> data) {
        this.data = data;
    }

    public Map<String, Project> getData() {
        return data;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public Optional<String> getMaintainerMobile() {
        return maintainerMobile;
    }

    public void setMaintainerMobile(Optional<String> maintainerMobile) {
        this.maintainerMobile = maintainerMobile;
    }
}
